package graph.day15;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

public class Leetcode_144 {

    List<Integer> res = new ArrayList<>();

    Stack<TreeNode> stack = new Stack<>();

    public List<Integer> preorderTraversal(TreeNode root) {
        if (root == null) return res;
        stack.push(root);
        while (!stack.isEmpty()) {
            TreeNode node = stack.pop();
            res.add(node.val);
            if (node.right != null) stack.push(node.right);
            if (node.left != null) stack.push(node.left);
        }
        return res;
    }

}
